package signGrammar.view;

import java.awt.Container;
import java.awt.GridBagConstraints;

public class CViewGridBox extends CViewBox {
	private static final long serialVersionUID = 1L;
	public CViewGridBox(BoxType boxType, Container... things) {
		super(boxType, things);
	}

	private int breakPoint = 1;
	public int getBreakPoint() {
		return breakPoint;
	}
	public CViewGridBox setBreakPoint(int breakPoint) {
		this.breakPoint = breakPoint - 1;
		return this;
	}

	protected int cycleInc(int toInc, int bPoint){
		return toInc % bPoint == 0 && toInc != 0 ? 0 : ++toInc;
	}
	
	protected GridBagConstraints incGridParam(GridBagConstraints c) {
		int result = 0;
		if( boxType == BoxType.HORIZONTAL ){
			result = cycleInc(c.gridx, breakPoint);
			if( result == 0 )
				c.gridy++;
			c.gridx = result;
		} else if( boxType == BoxType.VERTICAL ){
			result = cycleInc(c.gridy, breakPoint);
			if( result == 0 )
				c.gridx++;
			c.gridy = result;
		}
		return c;
	}
	
	protected GridBagConstraints updateConstraints(GridBagConstraints constraints){
		return incGridParam(constraints);
	}
}
